package com.ny.service.impl;

import com.ny.entity.Device;
import com.ny.mapper.UserMapper;
import com.ny.service.DeviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeviceServiceImpl implements DeviceService {
    
    private static final Logger logger = LoggerFactory.getLogger(DeviceServiceImpl.class);
    
    @Autowired
    private UserMapper userMapper;
    
    @Override
    public List<Device> getAllDevices() {
        List<Device> devices = userMapper.findAllDevices();
        logger.info("查询所有设备，结果数量: {}", devices.size());
        logger.debug("设备列表: {}", devices);
        return devices;
    }
    
    @Override
    public List<Device> getDevicesByName(String deviceName) {
        logger.info("根据名称查询设备: {}", deviceName);
        if (deviceName == null || deviceName.trim().isEmpty()) {
            return getAllDevices();
        }
        List<Device> devices = userMapper.findDevicesByName(deviceName);
        logger.info("根据名称 '{}' 查询到的设备数量: {}", deviceName, devices.size());
        return devices;
    }

    @Override
    public List<Device> findAll() {
        return null;
    }
}